package com.common.core.client;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EventPublisherClient {
    private final AsyncEventBus asyncEventBus;
    private final EventBus eventBus;

    @Autowired
    public EventPublisherClient(AsyncEventBus asyncEventBus, EventBus eventBus) {
        this.asyncEventBus = asyncEventBus;
        this.eventBus = eventBus;
    }

    // 发布异步事件
    public void postAsync(Object event) {
        asyncEventBus.post(event);
    }

    // 发布同步事件
    public void postSync(Object event) {
        eventBus.post(event);
    }
}
